package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.ChargeInvoiceRedEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 发票冲红表Provider
 *
 * @author generator
 * @date 2020-05-12 14:24
 */
public class ChargeInvoiceRedProvider {

    /**
     * 增加ChargeInvoiceRed
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String insertChargeInvoiceRed(@Param("entity") ChargeInvoiceRedEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" charge_invoice_red ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" invoice_code ", " #{entity.invoiceCode,jdbcType=VARCHAR} ");
                VALUES(" invoice_no ", " #{entity.invoiceNo,jdbcType=VARCHAR} ");
                VALUES(" invoice_title ", " #{entity.invoiceTitle,jdbcType=VARCHAR} ");
                VALUES(" invoice_charge ", " #{entity.invoiceCharge,jdbcType=DECIMAL} ");
                VALUES(" invoice_time ", " #{entity.invoiceTime,jdbcType=TIMESTAMP} ");
                VALUES(" invoice_state_code ", " #{entity.invoiceStateCode,jdbcType=TINYINT} ");
                VALUES(" invoice_cancel_no ", " #{entity.invoiceCancelNo,jdbcType=VARCHAR} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改ChargeInvoiceRed
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String updateChargeInvoiceRed(@Param("entity") ChargeInvoiceRedEntity entity) {
        return new SQL() {
            {
                UPDATE(" charge_invoice_red ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" invoice_code = #{entity.invoiceCode,jdbcType=VARCHAR} ");
                SET(" invoice_no = #{entity.invoiceNo,jdbcType=VARCHAR} ");
                SET(" invoice_title = #{entity.invoiceTitle,jdbcType=VARCHAR} ");
                SET(" invoice_charge = #{entity.invoiceCharge,jdbcType=DECIMAL} ");
                SET(" invoice_time = #{entity.invoiceTime,jdbcType=TIMESTAMP} ");
                SET(" invoice_state_code = #{entity.invoiceStateCode,jdbcType=TINYINT} ");
                SET(" invoice_cancel_no = #{entity.invoiceCancelNo,jdbcType=VARCHAR} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询ChargeInvoiceRed列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String listChargeInvoiceRed(@Param("entity") ChargeInvoiceRedEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,invoice_code,invoice_no,invoice_title,invoice_charge,invoice_time,invoice_state_code,invoice_cancel_no,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" charge_invoice_red ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getInvoiceCode() != null) {
                    WHERE(" invoice_code = #{entity.invoiceCode,jdbcType=VARCHAR} ");
                }

                if (entity.getInvoiceNo() != null) {
                    WHERE(" invoice_no = #{entity.invoiceNo,jdbcType=VARCHAR} ");
                }

                if (entity.getInvoiceTitle() != null) {
                    WHERE(" invoice_title = #{entity.invoiceTitle,jdbcType=VARCHAR} ");
                }

                if (entity.getInvoiceCharge() != null) {
                    WHERE(" invoice_charge = #{entity.invoiceCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getInvoiceTime() != null) {
                    WHERE(" invoice_time = #{entity.invoiceTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getInvoiceStateCode() != null) {
                    WHERE(" invoice_state_code = #{entity.invoiceStateCode,jdbcType=TINYINT} ");
                }

                if (entity.getInvoiceCancelNo() != null) {
                    WHERE(" invoice_cancel_no = #{entity.invoiceCancelNo,jdbcType=VARCHAR} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}